import axios from 'axios'
// eslint-disable-next-line no-unused-vars

axios.defaults.withCredentials = true
const service = axios.create({
  baseURL: 'http://39.100.101.91:8090/sdgs-api',
  timeout: 15000,
  validateStatus: (status => {
    return status > 100
  })
})
service.interceptors.request.use(config => {
  // 在发送请求之前做些什么
  return config
}, error => {
  // 对请求错误做些什么
  return Promise.reject(error)
})
service.interceptors.response.use(response => {
  return response.data
}, err => {
  return Promise.reject(err)
})

const request = (config) => {
  return service.request(config).then(res => {
    return res
  })
}
export const GET = (url, data, config) => {
  const CONF = {
    url: url,
    method: 'get',
    params: data,
  }
  return request({...CONF, ...config})
}
export const POST = (url, params, data, config) => {
  const CONF = {
    url: url,
    method: 'post',
    params,
    data,
  }
  return request({...CONF, ...config})
}
export const PUT = (url, params, data, config) => {
  const CONF = {
    url: url,
    headers: {
      'Content-Type': 'application/json'
    },
    method: 'put',
    params,
    data,
  }
  return request({...CONF, ...config})
}
export const DELETE = (url, params, data, config) => {
  const CONF = {
    url: url,
    method: 'delete',
    params,
    data
  }
  return request({...CONF, ...config})
}
